package behavior.strategy;

import java.math.BigDecimal;

/**
 * @author lzp
 * @Date:2023/3/7
 * @description: 策略上下文
 */
public class DiscountContext {

	/**
	 * 持有策略
	 */
	private DiscountStrategy strategy = new UserDiscountStrategy();

	/**
	 * 允许客户端设置新策略
	 * @param strategy
	 */
	public void setStrategy(DiscountStrategy strategy) {
		this.strategy = strategy;
	}

	public BigDecimal calculatePrice(BigDecimal total) {
		return total.subtract(this.strategy.getDiscount(total)).setScale(2);
	}

}
